Back-to-back Stem-and-Leaf with numbers


In [1]:
%matplotlib inline
from stemgraphic.num import stem_graphic
import pandas as pd
import numpy as np
import math

Loading the iris dataset


In [2]:
df = pd.read_csv('../datasets/iris.csv')

In [3]:
df.describe()


Out[3]:
sepal_length sepal_width petal_length petal_width
count 150.000000 150.000000 150.000000 150.000000
mean 5.843333 3.054000 3.758667 1.198667
std 0.828066 0.433594 1.764420 0.763161
min 4.300000 2.000000 1.000000 0.100000
25% 5.100000 2.800000 1.600000 0.300000
50% 5.800000 3.000000 4.350000 1.300000
75% 6.400000 3.300000 5.100000 1.800000
max 7.900000 4.400000 6.900000 2.500000

In [4]:
fig, ax = stem_graphic(df['sepal_length'],
                       random_state=42,
                       title='sepal_length')



In [5]:
fig, ax = stem_graphic(df['sepal_width'],
                       random_state=42,
                       mirror=True,
                       title='sepal_width')


Let's combined both variables in one back-to-back stem-and-leaf plot:


In [6]:
fig, ax = stem_graphic(df['sepal_length'],
                       df['sepal_width'],
                       random_state=42,
                       legend_pos=None, outliers=True)


And of course, we can save a pdf. Note the option needed:

fig.savefig('b2b_stem_graphic_numbers.pdf', bbox_inches='tight')

Inverting the two variables, we get


In [7]:
fig, ax = stem_graphic(df['sepal_width'],
                       df['sepal_length'],
                       random_state=42,
                       legend_pos=None)